package com.tools;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.login.R;


public class GoodNews extends LinearLayout {
    private Context mContext;
    private ImageView image;
    private TextView title;
    private TextView time;

    public GoodNews(Context context) {
        super(context);
        mContext = context;
        initView(context);
    }
    /**
     * 带有两个参数的构造方法，布局文件使用的时候调用
     */
    public GoodNews(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        mContext = context;
    }

    public GoodNews(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        mContext = context;
    }

    private void initView(Context context){
        //将打气筒根据自定义控件的布局文件，创建的view对象 挂载到当前类上面 然后显示
        View view = View.inflate(context, R.layout.good_news_item,this);
        title = (TextView) view.findViewById(R.id.good_news_title);
        time = (TextView) view.findViewById(R.id.good_news_time);
        image = (ImageView) view.findViewById(R.id.good_news_image);
    }

    /**
     * get set
     */
    public String getTitle(){
        return title.getText().toString();
    }

    public void setTitle(String text){
        title.setText(text);
    }

    public String getTime(){
        return time.getText().toString();
    }

    public void setTime(String text){
        time.setText(text);
    }

    public void setImage(int imageResource){
        image.setImageResource(imageResource);
    }
}